import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { Tabs, Badge, WhiteSpace } from 'antd-mobile';
import MessageListPage from './MessageListPage';
import DoctorListPage from './DoctorListPage';
import ConversationPage from './ConversationPage';
import RequestListPage from './RequestListPage';
import { StickyContainer, Sticky } from 'react-sticky';

const DoctorPage = (props) => {
   const { dispatch, unread, doctors } = props;
   const tabs = [
    { title: <Badge>消息</Badge>, sub: 'subcontent' },
    { title: <Badge text={doctors.length}>医生</Badge>, sub: 'subcontent' },
  ];
  // function filterHandler(key) {
        function filterHandler(tab,index) {
          
          if (index === 0) {
              dispatch({ 
                type: 'message/fetchMessages', 
                payload: { 
                  patientId: JSON.parse(localStorage.getItem("auth"+sessionStorage.getItem("hid"))).patientId
              } 
            });
          }

          if (index === 1) {
              dispatch({ 
                type: 'message/fetchDoctors', 
                payload: { 
                  patientId: JSON.parse(localStorage.getItem("auth"+sessionStorage.getItem("hid"))).patientId
              } 
            });
          }
        }

    return (
      <Tabs onChange={(tab, index) => filterHandler(tab,index)} tabs={tabs}>
          <div>
              <MessageListPage {...props} />
          </div>
          <div>
              <DoctorListPage {...props} />
          </div>
      </Tabs>
    );
};

export default connect(({ message}) => ({
  ...message,
}))(DoctorPage);

export {
  ConversationPage,
  RequestListPage,
};
